7F0C9DA4
	accepts: A0=p->sample,A1=width,A2=height,A3=p->final,SP+10=nibble3
ADDIU	SP,SP,FF98
LW	T6,0078 (SP)	;T6=nibble3 - type
SW	S2,0010 (SP)
SW	S1,000C (SP)
SW	S0,0008 (SP)
SLTIU	AT,T6,0009	;type should be 0-8
OR	S0,A1,R0	;S0=width
OR	S1,A0,R0	;S1=p->sample
OR	S2,A2,R0	;S2=height
SW	S3,0014 (SP)
OR	T2,A3,R0	;T2=p->final
OR	T1,A3,R0	;T1=p->final
OR	V1,A3,R0	;V1=p->final
BEQ	AT,R0,7F0CA874	;do nothing if it is a stupid type
OR	T0,R0,R0	;T0=0
SLL	T6,T6,0x2
LUI	AT,8006
ADDU	AT,AT,T6
LW	T6,BDC4 (AT)	;T6=8005BDC4+type offset: routine to generate final image
JR	T6
NOP	

7F0C9DF8:	type 0	32bit color
BLEZ	S2,7F0C9F90
OR	A3,R0,R0
ADDIU	T7,S0,0003
ANDI	T8,T7,0FFC
SLL	T9,T8,0x2
SW	T9,001C (SP)
BLEZ	S0,7F0C9F80
OR	A1,R0,R0
MULTU	S0,S2
ADDU	T4,S1,T0
ANDI	A2,S0,0003
SLL	T9,R0,0x2
ADDU	T1,T2,T9
OR	T5,A2,R0
ADDU	V0,S1,T0
MFLO	T3
SLL	T6,T3,0x2
SUBU	T6,T6,T3
ADDU	T7,T6,T0
SLL	T8,T3,0x1
ADDU	S3,T4,T8
ADDU	A0,T7,S1
BEQ	A2,R0,7F0C9EA8
ADDU	V1,T4,T3
LBU	T7,0000 (V0)
LBU	T6,0000 (A0)
ADDIU	A1,A1,0001
SLL	T8,T7,0x18
LBU	T7,0000 (V1)
OR	T9,T6,T8
ADDIU	T0,T0,0001
SLL	T6,T7,0x10
LBU	T7,0000 (S3)
OR	T8,T9,T6
ADDIU	V0,V0,0001
SLL	T9,T7,0x8
OR	T6,T8,T9
SW	T6,0000 (T1)
ADDIU	A0,A0,0001
ADDIU	V1,V1,0001
ADDIU	S3,S3,0001
BNE	T5,A1,7F0C9E58
ADDIU	T1,T1,0004
BEQ	A1,S0,7F0C9F80
SLL	T7,A1,0x2
ADDU	T1,T2,T7
LBU	T9,0000 (V0)
LBU	T8,0000 (A0)
ADDIU	A1,A1,0004
SLL	T6,T9,0x18
LBU	T9,0000 (V1)
OR	T7,T8,T6
ADDIU	T0,T0,0004
SLL	T8,T9,0x10
LBU	T9,0000 (S3)
OR	T6,T7,T8
ADDIU	V0,V0,0004
SLL	T7,T9,0x8
OR	T8,T6,T7
SW	T8,0000 (T1)
LBU	T6,FFFD (V0)
LBU	T9,0001 (A0)
ADDIU	A0,A0,0004
SLL	T7,T6,0x18
LBU	T6,0001 (V1)
OR	T8,T9,T7
ADDIU	V1,V1,0004
SLL	T9,T6,0x10
LBU	T6,0001 (S3)
OR	T7,T8,T9
ADDIU	S3,S3,0004
SLL	T8,T6,0x8
OR	T9,T7,T8
SW	T9,0004 (T1)
LBU	T7,FFFE (V0)
LBU	T6,FFFE (A0)
ADDIU	T1,T1,0010
SLL	T8,T7,0x18
LBU	T7,FFFE (V1)
OR	T9,T6,T8
SLL	T6,T7,0x10
LBU	T7,FFFE (S3)
OR	T8,T9,T6
SLL	T9,T7,0x8
OR	T6,T8,T9
SW	T6,FFF8 (T1)
LBU	T8,FFFF (V0)
LBU	T7,FFFF (A0)
SLL	T9,T8,0x18
LBU	T8,FFFF (V1)
OR	T6,T7,T9
SLL	T7,T8,0x10
LBU	T8,FFFF (S3)
OR	T9,T6,T7
SLL	T6,T8,0x8
OR	T7,T9,T6
BNE	A1,S0,7F0C9EB0
SW	T7,FFFC (T1)
LW	T8,001C (SP)
ADDIU	A3,A3,0001
BNE	A3,S2,7F0C9E10
ADDU	T2,T2,T8
ADDIU	T9,S0,0003
ANDI	T6,T9,0FFC
MULTU	T6,S2
MFLO	V0
SLL	T7,V0,0x2
BEQ	R0,R0,7F0CA878
OR	V0,T7,R0

7F0C9FAC:	type 2	32bit color (alpha set to 0xFF, so technically 24bit->32bit fixed alpha)
BLEZ	S2,7F0CA11C
OR	A3,R0,R0
ADDIU	T8,S0,0003
ANDI	T9,T8,0FFC	;WIDth=width to nearest word
SLL	T6,T9,0x2
SW	T6,001C (SP)	;save WIDth
BLEZ	S0,7F0CA10C
OR	A1,R0,R0
MULTU	S0,S2
ADDU	T7,S1,T0	;T7=p->samples + sampoff
ANDI	A2,S0,0003
SLL	T6,R0,0x2
ADDU	T1,T2,T6	;T1=p->final
OR	A0,A2,R0
ADDU	V0,S1,T0	;V0=p->samples + sampoff
MFLO	T3		;T3=width*height
SLL	T8,T3,0x1	;T8=width*height*2
ADDU	T9,T8,T0	;T9=width*height*2 + sampoff
ADDU	T4,T9,S1	;T4=width*height*2 + sampoff + p->samples
BEQ	A2,R0,7F0CA048
ADDU	V1,T7,T3	;V1=p->samples + sampoff + width*height
LBU	T9,0000 (V0)
LBU	T7,0000 (T4)
ADDIU	A1,A1,0001
SLL	T6,T9,0x18
LBU	T9,0000 (V1)
SLL	T8,T7,0x8
OR	T7,T8,T6
SLL	T8,T9,0x10
OR	T6,T7,T8
ORI	T9,T6,00FF
SW	T9,0000 (T1)
ADDIU	T0,T0,0001
ADDIU	V0,V0,0001
ADDIU	V1,V1,0001
ADDIU	T4,T4,0001
BNE	A0,A1,7F0CA000
ADDIU	T1,T1,0004
BEQ	A1,S0,7F0CA10C
SLL	T7,A1,0x2
ADDU	T1,T2,T7
LBU	T9,0000 (V0)
LBU	T8,0000 (T4)
ADDIU	A1,A1,0004
SLL	T7,T9,0x18
LBU	T9,0000 (V1)
SLL	T6,T8,0x8
OR	T8,T6,T7
SLL	T6,T9,0x10
OR	T7,T8,T6
ORI	T9,T7,00FF
SW	T9,0000 (T1)
LBU	T7,0001 (V0)
LBU	T8,0001 (T4)
ADDIU	T0,T0,0004
SLL	T9,T7,0x18
LBU	T7,0001 (V1)
SLL	T6,T8,0x8
OR	T8,T6,T9
SLL	T6,T7,0x10
OR	T9,T8,T6
ORI	T7,T9,00FF
SW	T7,0004 (T1)
LBU	T9,0002 (V0)
LBU	T8,0002 (T4)
ADDIU	V0,V0,0004
SLL	T7,T9,0x18
LBU	T9,0002 (V1)
SLL	T6,T8,0x8
OR	T8,T6,T7
SLL	T6,T9,0x10
OR	T7,T8,T6
ORI	T9,T7,00FF
SW	T9,0008 (T1)
LBU	T7,FFFF (V0)
LBU	T8,0003 (T4)
ADDIU	V1,V1,0004
SLL	T9,T7,0x18
LBU	T7,FFFF (V1)
SLL	T6,T8,0x8
OR	T8,T6,T9
SLL	T6,T7,0x10
OR	T9,T8,T6
ORI	T7,T9,00FF
SW	T7,000C (T1)
ADDIU	T4,T4,0004
BNE	A1,S0,7F0CA050
ADDIU	T1,T1,0010
LW	T8,001C (SP)
ADDIU	A3,A3,0001
BNE	A3,S2,7F0C9FC4
ADDU	T2,T2,T8
ADDIU	T6,S0,0003
ANDI	T9,T6,0FFC
MULTU	T9,S2
MFLO	V0
SLL	T7,V0,0x2
BEQ	R0,R0,7F0CA878
OR	V0,T7,R0

7F0CA138:	type 1	16bit color
BLEZ	S2,7F0CA2D0
OR	A3,R0,R0
ADDIU	T8,S0,0003
ANDI	T6,T8,0FFC
SLL	T9,T6,0x1
SW	T9,001C (SP)
BLEZ	S0,7F0CA2C0
OR	A1,R0,R0
MULTU	S0,S2
ADDU	T4,S1,T0
ANDI	A2,S0,0003
SLL	T9,R0,0x1
ADDU	T2,T1,T9
OR	T5,A2,R0
ADDU	V0,S1,T0
MFLO	T3		;T3=width*height
SLL	T7,T3,0x2
SUBU	T7,T7,T3	;T7=width*height*3
ADDU	T8,T7,T0	;T8=width*height*3 + sampoff
SLL	T6,T3,0x1	;T6=width*height*2
ADDU	S3,T4,T6
ADDU	A0,T8,S1	;A0=p->sampA	p->sample + width*height*3 + sampoff
BEQ	A2,R0,7F0CA1E8
ADDU	V1,T4,T3
LBU	T8,0000 (V0)	;T8=sampR
LBU	T7,0000 (A0)	;T7=sampA
ADDIU	A1,A1,0001
SLL	T6,T8,0xB	;T6=red*0x800
LBU	T8,0000 (V1)	;T8=sampG
OR	T9,T7,T6	;T9=red*0x800 | alpha
ADDIU	T0,T0,0001
SLL	T7,T8,0x6	;T7=green*0x40
LBU	T8,0000 (S3)	;T8=sampB
OR	T6,T9,T7	;T6=red*0x800 | green*0x40 | alpha
ADDIU	V0,V0,0001
SLL	T9,T8,0x1	;T9=blue*2
OR	T7,T6,T9	;T7=red*0x800 | green*0x40 | blue*2 | alpha
SH	T7,0000 (T2)
ADDIU	A0,A0,0001
ADDIU	V1,V1,0001
ADDIU	S3,S3,0001
BNE	T5,A1,7F0CA198
ADDIU	T2,T2,0002
BEQ	A1,S0,7F0CA2C0
SLL	T8,A1,0x1
ADDU	T2,T1,T8
LBU	T9,0000 (V0)
LBU	T6,0000 (A0)
ADDIU	A1,A1,0004
SLL	T7,T9,0xB
LBU	T9,0000 (V1)
OR	T8,T6,T7
ADDIU	T0,T0,0004
SLL	T6,T9,0x6
LBU	T9,0000 (S3)
OR	T7,T8,T6
ADDIU	V0,V0,0004
SLL	T8,T9,0x1
OR	T6,T7,T8
SH	T6,0000 (T2)
LBU	T7,FFFD (V0)
LBU	T9,0001 (A0)
ADDIU	A0,A0,0004
SLL	T8,T7,0xB
LBU	T7,0001 (V1)
OR	T6,T9,T8
ADDIU	V1,V1,0004
SLL	T9,T7,0x6
LBU	T7,0001 (S3)
OR	T8,T6,T9
ADDIU	S3,S3,0004
SLL	T6,T7,0x1
OR	T9,T8,T6
SH	T9,0002 (T2)
LBU	T8,FFFE (V0)
LBU	T7,FFFE (A0)
ADDIU	T2,T2,0008
SLL	T6,T8,0xB
LBU	T8,FFFE (V1)
OR	T9,T7,T6
SLL	T7,T8,0x6
LBU	T8,FFFE (S3)
OR	T6,T9,T7
SLL	T9,T8,0x1
OR	T7,T6,T9
SH	T7,FFFC (T2)
LBU	T6,FFFF (V0)
LBU	T8,FFFF (A0)
SLL	T9,T6,0xB
LBU	T6,FFFF (V1)
OR	T7,T8,T9
SLL	T8,T6,0x6
LBU	T6,FFFF (S3)
OR	T9,T7,T8
SLL	T7,T6,0x1
OR	T8,T9,T7
BNE	A1,S0,7F0CA1F0
SH	T8,FFFE (T2)
LW	T6,001C (SP)
ADDIU	A3,A3,0001
BNE	A3,S2,7F0CA150
ADDU	T1,T1,T6
ADDIU	T9,S0,0003
ANDI	T7,T9,0FFC
MULTU	T7,S2
MFLO	V0
SLL	T8,V0,0x1
BEQ	R0,R0,7F0CA878
OR	V0,T8,R0

7F0CA2EC:	type 4	IA-16bit
BLEZ	S2,7F0CA3E4	;branch if height is nonexistant
OR	A3,R0,R0	;A3=0	linecount
ADDIU	T6,S0,0003
ANDI	T9,T6,0FFC	;T9=WIDth	width to nearest word boundry
SLL	T7,T9,0x1	;T7=WIDth*2	linewidth
SW	T7,001C (SP)	;save linewidth
//7F0CA304:	copy each line to final
BLEZ	S0,7F0CA3D4	;branch if width is stupid
OR	A1,R0,R0	;A1=0	count
MULTU	S0,S2
ANDI	A2,S0,0003	;A2=extra 'non-aligned' bytes
SLL	T9,R0,0x1	;T9=0
ADDU	T2,T1,T9	;T2=p->final
OR	V1,A2,R0	;V1=A2: extra 'non-aligned' bytes
ADDU	V0,S1,T0	;V0=p->sample + sampoff	p->sampI
MFLO	T8		;T8=width*height
ADDU	T6,T0,T8	;T6=sampoff + width*height
BEQ	A2,R0,7F0CA364
ADDU	T3,T6,S1	;T3=sampoff + width*height + p->sample	p->sampA
//7F0CA334:	copy hangers-on
LBU	T8,0000 (V0)	;T8=sampI
LBU	T7,0000 (T3)	;T7=sampA
ADDIU	A1,A1,0001	;count++
SLL	T6,T8,0x8	;T6=sampI*0x100
OR	T9,T7,T6	;T9=sampI*0x100 | sampA
SH	T9,0000 (T2)	;save IA->final
ADDIU	T0,T0,0001	;sampoff++
ADDIU	V0,V0,0001	;p->sampI++
ADDIU	T3,T3,0001	;p->sampA++
BNE	V1,A1,7F0CA334	;branch for more unaligned bytes
ADDIU	T2,T2,0002	;p->final+=2
BEQ	A1,S0,7F0CA3D4	;branch if at EOL
//7F0CA364:
SLL	T8,A1,0x1	;T8=count*2
ADDU	T2,T1,T8	;T2=p->final + count*2
//7F0CA36C:	copy entries four at a time
LBU	T6,0000 (V0)
LBU	T7,0000 (T3)
ADDIU	A1,A1,0004
SLL	T9,T6,0x8
OR	T8,T7,T9
SH	T8,0000 (T2)
LBU	T7,0001 (V0)
LBU	T6,0001 (T3)
ADDIU	T0,T0,0004
SLL	T9,T7,0x8
OR	T8,T6,T9
SH	T8,0002 (T2)
LBU	T6,0002 (V0)
LBU	T7,0002 (T3)
ADDIU	V0,V0,0004
SLL	T9,T6,0x8
OR	T8,T7,T9
SH	T8,0004 (T2)
LBU	T7,FFFF (V0)
LBU	T6,0003 (T3)
ADDIU	T3,T3,0004
SLL	T9,T7,0x8
OR	T8,T6,T9
SH	T8,0006 (T2)
BNE	A1,S0,7F0CA36C
ADDIU	T2,T2,0008
//7F0CA3D4	loop for each line
LW	T7,001C (SP)
ADDIU	A3,A3,0001
BNE	A3,S2,7F0CA304
ADDU	T1,T1,T7
//7F0CA3E4:	return final size
ADDIU	T6,S0,0003
ANDI	T9,T6,0FFC
MULTU	T9,S2
MFLO	V0
SLL	T8,V0,0x1
BEQ	R0,R0,7F0CA878
OR	V0,T8,R0	;V0=WIDth*height*2	final size

7F0CA400:	type 3	15bit color (alpha set to 1)
BLEZ	S2,7F0CA570	;branch if height is nonexistant
OR	A3,R0,R0	;A3=0	linecount
ADDIU	T7,S0,0003
ANDI	T6,T7,0FFC	;T6=WIDth	width to nearest word
SLL	T9,T6,0x1	;T9=linewidth	WIDth*2
SW	T9,001C (SP)	;save linewidth
//7F0CA418:
BLEZ	S0,7F0CA560	;branch if width is stupid
OR	A1,R0,R0	;A1=0	count
MULTU	S0,S2
ADDU	T8,S1,T0	;T8=p->sample + sampoff
ANDI	A2,S0,0003	;'non word-aligned' bytes
SLL	T9,R0,0x1	;T9=0
ADDU	T2,T1,T9	;T2=p->final
OR	A0,A2,R0	;A0=A2: extra bytes
ADDU	V0,S1,T0	;V0=p->sample + sampoff	p->sampR
MFLO	T3		;T3=width*height	size of original
SLL	T7,T3,0x1	;T7=width*height*2
ADDU	T6,T7,T0	;T6=width*height*2 + sampoff
ADDU	T4,T6,S1	;T4=width*height*2 + sampoff + p->sample	p->sampB
BEQ	A2,R0,7F0CA49C	;branch if there are no extra bytes to deal with
ADDU	V1,T8,T3	;V1=p->sample + sampoff + width*height	p->sampG
//7F0CA454:	save non-aligned 16bit colors
LBU	T6,0000 (V0)	;T6=sampR
LBU	T8,0000 (T4)	;T8=sampB
ADDIU	A1,A1,0001	;count++
SLL	T9,T6,0xB	;T9=red*0x800
LBU	T6,0000 (V1)	;T6=sampG
SLL	T7,T8,0x1	;T7=blue*2
OR	T8,T7,T9	;T8=red+blue
SLL	T7,T6,0x6	;T7=green*0x40
OR	T9,T8,T7	;T9=red+green+blue
ORI	T6,T9,0001	;T6=red+green+blue+alpha
SH	T6,0000 (T2)	;save 16bit color to final
ADDIU	T0,T0,0001	;sampoff++
ADDIU	V0,V0,0001	;p->sampR++
ADDIU	V1,V1,0001	;p->sampG++
ADDIU	T4,T4,0001	;p->sampB++
BNE	A0,A1,7F0CA454	;branch for any additional hangers-on
ADDIU	T2,T2,0002	;p->final+=2
BEQ	A1,S0,7F0CA560	;skip if line is complete
//7F0CA49C:
SLL	T8,A1,0x1	;T8=count*2
ADDU	T2,T1,T8	;T2=p->final + count*2
//7F0CA4A4:	write sets of 4 until line complete
LBU	T6,0000 (V0)
LBU	T7,0000 (T4)
ADDIU	A1,A1,0004
SLL	T8,T6,0xB
LBU	T6,0000 (V1)
SLL	T9,T7,0x1
OR	T7,T9,T8
SLL	T9,T6,0x6
OR	T8,T7,T9
ORI	T6,T8,0001
SH	T6,0000 (T2)
LBU	T8,0001 (V0)
LBU	T7,0001 (T4)
ADDIU	T0,T0,0004
SLL	T6,T8,0xB
LBU	T8,0001 (V1)
SLL	T9,T7,0x1
OR	T7,T9,T6
SLL	T9,T8,0x6
OR	T6,T7,T9
ORI	T8,T6,0001
SH	T8,0002 (T2)
LBU	T6,0002 (V0)
LBU	T7,0002 (T4)
ADDIU	V0,V0,0004
SLL	T8,T6,0xB
LBU	T6,0002 (V1)
SLL	T9,T7,0x1
OR	T7,T9,T8
SLL	T9,T6,0x6
OR	T8,T7,T9
ORI	T6,T8,0001
SH	T6,0004 (T2)
LBU	T8,FFFF (V0)
LBU	T7,0003 (T4)
ADDIU	V1,V1,0004
SLL	T6,T8,0xB
LBU	T8,FFFF (V1)
SLL	T9,T7,0x1
OR	T7,T9,T6
SLL	T9,T8,0x6
OR	T6,T7,T9
ORI	T8,T6,0001
SH	T8,0006 (T2)
ADDIU	T4,T4,0004
BNE	A1,S0,7F0CA4A4	;loop until line complete
ADDIU	T2,T2,0008
//7F0CA560:	loop for each line
LW	T7,001C (SP)
ADDIU	A3,A3,0001
BNE	A3,S2,7F0CA418
ADDU	T1,T1,T7
//7F0CA570:	return final size
ADDIU	T9,S0,0003
ANDI	T6,T9,0FFC
MULTU	T6,S2
MFLO	V0		;V0=WIDth*height
SLL	T8,V0,0x1
BEQ	R0,R0,7F0CA878
OR	V0,T8,R0	;V0=WIDth*height*2

7F0CA58C:	type 5	IA-8bit
BLEZ	S2,7F0CA674	;branch if height is nonexistant
OR	A3,R0,R0	;A3=0	linecount
ADDIU	A0,S0,0007	;A0=width+7
ANDI	T7,A0,0FF8
OR	A0,T7,R0	;A0=width pushed to nearest doubleword (WIDth)
//7F0CA5A0:
BLEZ	S0,7F0CA668	;branch if width is stupid
OR	A1,R0,R0	;A1=0	count
MULTU	S0,S2
ANDI	A2,S0,0003	;A2=two trailing bits of width
OR	T2,A2,R0	;T2=two trailing bits of width
ADDU	V0,S1,T0	;V0=p->sample + sampoff
ADDU	T1,V1,R0	;T1=V1: p->final
MFLO	T9		;T9=width*height
ADDU	T6,T0,T9	;T6=offset to sampalpha	sampoff+width*height
BEQ	A2,R0,7F0CA5FC
ADDU	T3,T6,S1	;T3=p->sample + sampoff + width*height (alpha? - from 7F0C9A48 probably)
//7F0CA5CC:	copy excess non-word bytes (0-3)
LBU	T7,0000 (V0)	;T7=value from sample
LBU	T8,0000 (T3)	;T8=alpha? value
ADDIU	A1,A1,0001	;A1++	count++
SLL	T9,T7,0x4	;T9=val*0x10
OR	T6,T8,T9	;T6=val*0x10 + 'alpha' bit
SB	T6,0000 (T1)	;converted val->final
ADDIU	T0,T0,0001	;sampoffset++
ADDIU	V0,V0,0001	;p->sample++
ADDIU	T3,T3,0001	;p->sampalpha++
BNE	T2,A1,7F0CA5CC	;loop until remaining bytes are copied
ADDIU	T1,T1,0001	;p->final++
BEQ	A1,S0,7F0CA668	;skip if count=width
//7F0CA5FC:
ADDU	T1,V1,A1	;T1=p->final+count
//7F0CA600:	copy a 'word' from samp->final
LBU	T8,0000 (V0)	;T8=value from sample
LBU	T7,0000 (T3)	;T7=alpha? value
ADDIU	A1,A1,0004	;count+=4
SLL	T9,T8,0x4	;T9=val*0x10
OR	T6,T7,T9	;T6=val*0x10 + 'alpha' bit
SB	T6,0000 (T1)	;converted val->final
LBU	T7,0001 (V0)	;T7=next value from sample
LBU	T8,0001 (T3)	;T8=next alpha? value
ADDIU	T0,T0,0004	;sampoffset+=4
SLL	T9,T7,0x4	;T9=val*0x10
OR	T6,T8,T9	;T6=val*0x10 + 'alpha' bit
SB	T6,0001 (T1)	;converted val->final
LBU	T8,0002 (V0)	;T8=next value from sample
LBU	T7,0002 (T3)	;T7=next alpha? value
ADDIU	V0,V0,0004	;p->sample+=4
SLL	T9,T8,0x4	;T9=val*0x10
OR	T6,T7,T9	;T6=val*0x10 + 'alpha' bit
SB	T6,0002 (T1)	;converted val->final
LBU	T7,FFFF (V0)	;T7=next value from sample
LBU	T8,0003 (T3)	;T8=next alpha? value
ADDIU	T3,T3,0004	;p->sampalpha+=4
SLL	T9,T7,0x4	;T9=val*0x10
OR	T6,T8,T9	;T6=val*0x10 + 'alpha' bit
SB	T6,0003 (T1)	;converted val->final
BNE	A1,S0,7F0CA600	;loop for each element in line
ADDIU	T1,T1,0004	;p->final+=4
//7F0CA668:	loop for each line
ADDIU	A3,A3,0001	;A3++	linecount++
BNE	A3,S2,7F0CA5A0	;loop while linecount<height
ADDU	V1,V1,A0	;V1+=WIDth	posOUT+=WIDth
//7F0CA674:	this is the end
ADDIU	T7,S0,0007
ANDI	T8,T7,0FF8	;T8=WIDth
MULTU	T8,S2
MFLO	V0		;V0=WIDth*height	size of actual image
BEQ	R0,R0,7F0CA87C
LW	S0,0008 (SP)

7F0CA68C:	type 7	I-8bit	(direct copy)
BLEZ	S2,7F0CA720	;branch if height is nonexistant
OR	A3,R0,R0	;A3=0	linecount
ADDIU	A0,S0,0007
ANDI	T9,A0,0FF8	;T9=WIDth
OR	A0,T9,R0	;A0=WIDth
//7F0CA6A0:	copy a line from source to final
BLEZ	S0,7F0CA714	;kill if width is stupid
OR	A1,R0,R0	;A1=0	count
ANDI	A2,S0,0003
BEQ	A2,R0,7F0CA6DC	;skip if the data is 'word aligned'
ADDU	V0,S1,T0	;V0=p->sample + sampoff
OR	T2,A2,R0	;T2=A2: total bytes to copy
ADDU	T1,V1,R0	;T1=V1: p->final
//7F0CA6BC:	copy bytes to 'word boundry'
LBU	T6,0000 (V0)	;T6=value from sample
ADDIU	A1,A1,0001	;A1++	count++
ADDIU	T0,T0,0001	;sampoff++
ADDIU	V0,V0,0001	;p->sample++
ADDIU	T1,T1,0001	;p->final++
BNE	T2,A1,7F0CA6BC	;loop for each remaining byte
SB	T6,FFFF (T1)	;save val to final
BEQ	A1,S0,7F0CA714	;skip if count=bytes in a line
//7F0CA6DC:
ADDU	T1,V1,A1	;T1=p->final+count
//7F0CA6E0:	copy a 'word' to final
LBU	T7,0000 (V0)
ADDIU	A1,A1,0004
ADDIU	T0,T0,0004
SB	T7,0000 (T1)
LBU	T8,0001 (V0)
ADDIU	V0,V0,0004
ADDIU	T1,T1,0004
SB	T8,FFFD (T1)
LBU	T9,FFFE (V0)
SB	T9,FFFE (T1)
LBU	T6,FFFF (V0)
BNE	A1,S0,7F0CA6E0
SB	T6,FFFF (T1)
//7F0CA714:	repeat for each line
ADDIU	A3,A3,0001
BNE	A3,S2,7F0CA6A0
ADDU	V1,V1,A0
//7F0CA720:
ADDIU	T7,S0,0007
ANDI	T8,T7,0FF8	;T8=WIDth
MULTU	T8,S2
MFLO	V0		;V0=size of final image
BEQ	R0,R0,7F0CA87C
LW	S0,0008 (SP)

7F0CA738:	type 6	IA-4bit
BLEZ	S2,7F0CA7D4	;branch if height is nonexistant
OR	A3,R0,R0	;A3=linecount
ADDIU	A2,S0,000F
ANDI	T9,A2,0FF0	;T2=WIDth	width to the nearest 0x10 boundry
OR	A2,T9,R0	;A2=T9: WIDth
ANDI	T1,S0,0001	;T1=TRUE if width is odd
//7F0CA750:	loop for each line
BLEZ	S0,7F0CA7C0	;skip if width is stupid
OR	A1,R0,R0	;A1=0	count
MULTU	S0,S2
ADDU	V0,S1,T0	;V0=p->sample + sampoff
MFLO	T6		;T6=width*height
SLL	T7,T6,0x2
SUBU	T7,T7,T6	;T7=width*height*3
ADDU	T8,T7,T0	;T8=width*height*3 + sampoff
ADDU	A0,T8,S1	;A0=width*height*3 + sampoff + p->sample
//7F0CA774:	copy bytes in line to final
LBU	T6,0000 (V0)	;T6=sample[0]
LBU	T9,0001 (A0)	;T9=sampalpha[1]
ADDIU	T0,T0,0002	;sampoff+=2
SLL	T7,T6,0x5	;T7=val * 0x20
LBU	T6,0000 (A0)	;T6=sampalpha[0]
OR	T8,T9,T7	;T8=sampalpha[1] | val*0x20
ADDIU	V0,V0,0002	;p->sample+2
SLL	T9,T6,0x4	;T9=sampalpha[0]*0x10
LBU	T6,FFFF (V0)	;T6=sample[1]
OR	T7,T8,T9	;T7=val*0x20 | sampalpha[0]*0x10 | sampalpha[1]
ADDIU	A0,A0,0002	;p->sampalpha+2
SLL	T8,T6,0x1	;T8=sample[1]*0x2
SRA	T6,A1,0x1	;T6=count/2
ADDIU	A1,A1,0002	;count+=2
OR	T9,T7,T8	;T9=val*0x20 | sampalpha[0]*0x10 | sample[1]*0x2 | sampalpha[1]
SLT	AT,A1,S0
ADDU	T7,V1,T6	;T7=p->final + count/2
BNEZ	AT,7F0CA774	;branch if more more elements in this line
SB	T9,0000 (T7)	;save value to final
//7F0CA7C0:
BEQ	T1,R0,7F0CA7CC	;branch if width is odd...
ADDIU	A3,A3,0001	;linecount++
ADDIU	T0,T0,FFFF	;sampoff--
//7F0CA7CC:
BNE	A3,S2,7F0CA750	;loop for each line
ADDU	V1,V1,A2	;p->final+=WIDth
//7F0CA7D4:
ADDIU	T8,S0,000F
ANDI	T6,T8,0FF0	;T6=WIDth
SRA	T9,T6,0x1	;T9=WIDth/2
MULTU	T9,S2
MFLO	V0		;V0=WIDth/2 * height
BEQ	R0,R0,7F0CA87C
LW	S0,0008 (SP)

7F0CA7F0:	type 8	I-4bit
BLEZ	S2,7F0CA858	;branch if height is nonexistant
OR	A3,R0,R0	;A3=linecount
ADDIU	A0,S0,000F
ANDI	T7,A0,0FF0
SRA	A0,T7,0x1	;A0=WIDth/2	width->nearest 0x10, divided by 2
ANDI	T1,S0,0001	;T1 TRUE if width odd
BLEZ	S0,7F0CA844	;branch if width is stupid
OR	A1,R0,R0	;A1=0	count
ADDU	V0,S1,T0	;V0=p->sample + sampoff
//7F0CA814:
LBU	T9,0000 (V0)	;T9=sample[0]
LBU	T6,0001 (V0)	;T6=sample[1]
ADDIU	T0,T0,0002	;sampoff+=2
SLL	T7,T9,0x4	;T7=sample[0]*0x10
SRA	T9,A1,0x1	;T9=count/2
ADDIU	A1,A1,0002	;count+=2
OR	T8,T6,T7	;T8=sample[0]*0x10 | sample[1]
SLT	AT,A1,S0
ADDU	T6,V1,T9	;T6=p->final+count/2
SB	T8,0000 (T6)	;save value to final
BNEZ	AT,7F0CA814	;branch if more elements in line
ADDIU	V0,V0,0002	;p->sample+2
//7F0CA844:	loop for each line
BEQ	T1,R0,7F0CA850	;don't subtract 1 if odd
ADDIU	A3,A3,0001	;linenum++
ADDIU	T0,T0,FFFF	;sampoff--
//7F0CA850:
BNE	A3,S2,7F0CA808	;loop for each line
ADDU	V1,V1,A0	;V1=p->final+WIDth
//7F0CA858:
ADDIU	T7,S0,000F
ANDI	T9,T7,0FF0
SRA	T8,T9,0x1
MULTU	T8,S2
MFLO	V0		;V0=WIDth/2 * height
BEQ	R0,R0,7F0CA87C
LW	S0,0008 (SP)

//7F0CA874:	tried and died...
OR	V0,R0,R0	;V0=return NULL size
LW	S0,0008 (SP)
//7F0CA87C:
LW	S1,000C (SP)
LW	S2,0010 (SP)
LW	S3,0014 (SP)
JR	RA
ADDIU	SP,SP,0068
